<?php
/**注意此文档为UTF-8的编码.
 * Created on 2010-9-12
 *
 * @author EXT <isrn@qq.com>
 *
 */
include ('../../includes/global.php');
include ('../global.php');
include ("../power.php");
function grv($type,$blm,$dvalue=false){
	//print_r($type);
	if($dvalue){
		return $dvalue;
		}else{
		switch($type){
				case 'function':{
					$a=explode('#',$blm);
					return $a[0]($a[1]);
					break;
					}
				case '$_GET':{
					return	$_GET[$blm];
					break;
					}
				case '$_SESSION':{
					return	$_SESSION[$blm];
					break;
					}
				case '$_POST':{
					return	$_POST[$blm];
					break;
					}
				case '$_COOKIE':{
					return	$_COOKIE[$blm];
					break;
					}
				case '$_SERVER':{
					return	$_SERVER[$blm];
					break;
					}
				case '$_ENV':{
					return	$_ENV[$blm];
					break;
					}
				case '$_FILES':{
					return	$_FILES[$blm];
					break;
					}
				case '0':{
					return $blm;
					break;
					}
				case '1':{
					break;
					}
				default:{
					return $blm;
					break;
					}
			
				}
			}
	}
$dbcfg=Sys::Gp(array('dbcfg','sevenel'));

		$tree_id = $_GET['tid'];
		Tr($_GET['tid'],'tid');
		Tr($_GET['bdtid'],'bdtid');
		Tr($_GET['bdid'],'bdid');
		$field=Dgd(array(
		  'db'=>'d_sevenel',
		  'cd'=>"tid = $tree_id and fname like '".$_GET['fname']."' ",
		  'tn'=>"fld",
		  'limit'=>1

		));
			$tree=Dgd(array(
			  'db'=>'d_sevenel',
			  'cd'=>"id = $tree_id",
			  'tn'=>"tree",
			  'limit'=>1
			));
			$tname=gettabname($tree['table'],$dbcfg['prefix'],true);
			Tr($tname,'tname');
		if($_GET['id']){
			Tr($_GET['id'],'id');
				$fdada=Dgd(array(
					  'db'=>'d_sevenel',
					  'cd'=>" id = '".$_GET['id']."' and del != '1' ",
					  'tn'=>"$tname",
					  'limit'=>1
					));
				Tr($fdada['gid'],'gid');
				Tr(preg_replace("/[\s]{2,}/","",$fdada['lg']),'lg');
				}


switch($_REQUEST['op']){
	/*	case 'load':{
		ext_request('ok');
		break;}
	*/
	
	case 'show':{
		    $value=$field;
			if($value['cfg']!=''){
				$config =json_decode($value['cfg'],true);
			}else{$config =''; }
			$config['STR']=str_replace("\r","",$config['STR']);
			$config['STR']=str_replace("\n","",$config['STR']);
			$config['STR']=str_replace("\t","",$config['STR']);
			switch($value['type']){
				case 'hidden':{
						$js[$value['fname']] ="{
							xtype: 'hidden',
								value:\"".(grv($value['qzfs'],$value['blm'],adxx($fdada[$value['fname']])))."\",
								".(($config['STR'])?("".$config['STR'].""):(""))."
							name: '".$value['fname']."'
							}";
				break;}
				case 'textfield':{
						$js[$value['fname']] ="{
							xtype: 'textfield',
							value:\"".(grv($value['qzfs'],$value['blm'],adxx($fdada[$value['fname']])))."\",
							fieldLabel:'".$value['name']."',
							".(($value['id'])?("id:'".$value['id']."',"):(""))."
							".(($value['width'])?("width:'".$value['width']."px',"):("grow:true,growMin:68,growMax:300,"))."
							".((!$value['yxwk'])?("allowBlank:false,blankText:'".adxx($value['ts'])."',"):(""))."
							".(($config['readonly'])?("readOnly:'true',"):(""))."
							".(($config['STR'])?("".$config['STR'].""):(""))."
							".$back."
							name: '".$value['fname']."'
							}";
				break;}
				case 'password':{
						$js[$value['fname']] ="{
							xtype: 'textfield',
							value:\"".(grv($value['qzfs'],$value['blm'],adxx($fdada[$value['fname']])))."\",
							fieldLabel:'".$value['name']."',
							inputType: 'password',allowBlank:false,blankText:'密码不能为空',
							id: '".$value['fname']."',
							".(($value['width'])?("width:'".$value['width']."px',"):("width:'100px',"))."
							".(($config['STR'])?("".$config['STR'].""):(""))."
							".$back."name: '".$value['fname']."'
							},{
							xtype: 'textfield',
							value:\"".(grv($value['qzfs'],$value['blm'],adxx($fdada[$value['fname']])))."\",
							fieldLabel:'确认".$value['name']."',
							inputType: 'password',allowBlank:false,blankText:'密码不能为空',
							vtype: 'password',
							".(($value['width'])?("width:'".$value['width']."px',"):("width:'100px',"))."
							".(($config['STR'])?("".$config['STR'].""):(""))."
							initialPassField: '".$value['fname']."',
							".$back."name: '".$value['fname']."-cfrm'
							}";
		        		$plugurl[] = '/Plug-in/ext/adv-vtypes.js';

							break;}
				case 'fileup':{
					if($fdada[$value['fname']]==''){
						$fdada[$value['fname']]='zwtp.jpg';
						}
										$dvalue=array( 0=>array('rar','zip','tar','.tz'),
													   1=>array('jpg','gif','png','bmp'),
													   2=>array('mp3','mp4','avi','wmv','mid','.rm','mvb','mov','wma','wav'),
													   3=>array('doc','xls','txt','ocx','lsx','ppt','pdf','chm'),
													   4=>array('doc','xls','txt','ocx','lsx','ppt','pdf','chm','mp3','mp4','avi','wmv','mid','.rm','mvb','mov','wma','wav','jpg','gif','png','bmp','rar','zip','tar','.tz')		   
															   );
										$otype=substr(strtolower($fdada[$value['fname']]),-3);
												if(in_array($otype,$dvalue[0])){
												$zs="<a href=\"/uplods/pic/".$fdada[$value['fname']]."\" target=\'_blank\'><img src=\"../img/archive.png\">下载[Download]</a>";
													}
												if(in_array($otype,$dvalue[1])){
													if($config['sypic']==1||$config['sytxt']==1){
													$zs="<img src=\"/uplods/sytp/".$fdada[$value['fname']]."\" >";	
															}else{
													$zs="<img src=\"/uplods/pic/".$fdada[$value['fname']]."\" >";	
																}
													}
												if(in_array($otype,$dvalue[2])){
												$zs="<a href=\"/uplods/pic/".$fdada[$value['fname']]."\" target=\'_blank\'><img src=\"../img/film_link.png\">下载[Download]</a>";
													}
												if(in_array($otype,$dvalue[3])){
												$zs="<a href=\"/uplods/pic/".$fdada[$value['fname']]."\" target=\'_blank\'><img src=\"../img/report_word.png\">下载[Download]</a>";
													}
					$qk=" <a href=\"#\"  onclick=qkzd(\"".$fdada['id']."\",\"".$value['fname']."\") ><img src=\"../img/001_02.gif\">清空此附件</a>";	
						$js[$value['fname']] ="{
							xtype: 'textfield',
							fieldLabel:'".$value['name']."',
							inputType: 'file',
							".(($value['id'])?("id:'".$value['id']."',"):(""))."
							width:'150',
							".(($config['STR'])?("".$config['STR'].""):(""))."
							".$back."name: '".$value['fname']."'
							},{".$back."html:'<div style=\"float:left;width:300px;\" align=center>".$zs."".$qk."</div>'}";
				break;}
				case 'textarea':{
						$js[$value['fname']] =preg_replace("/[\s]{2,}/","","{
							xtype: 'textarea',
							value:\"".(grv($value['qzfs'],$value['blm'],adxx($fdada[$value['fname']])))."\",
							fieldLabel:'".$value['name']."',
							grow:true,
							".(($value['id'])?("id:'".$value['id']."',"):(""))."
							".(($value['width'])?("width:'".$value['width']."px',"):("width:'400px',"))."
							".((!$value['yxwk'])?("allowBlank:false,blankText:'".adxx($value['ts'])."',"):(""))."
							".(($config['readonly'])?("readOnly:'true',"):(""))."
							".(($config['STR'])?("".$config['STR'].""):(""))."
							".$back."
							name: '".$value['fname']."'
							}");
				break;}
				case 'htmleditor':{
						$js[$value['fname']] =preg_replace("/[\s]{2,}/","","{
							xtype: 'htmleditor',
							value:\"".(grv($value['qzfs'],$value['blm'],adxx($fdada[$value['fname']])))."\",
							fieldLabel:'".$value['name']."',
							".(($value['id'])?("id:'".$value['id']."',"):(""))."
							".(($value['width'])?("width:".$value['width'].","):("anchor:'98%',"))."
							".(($config['height'])?("height:".$config['height'].","):(""))."
							".(($config['STR'])?("".$config['STR'].""):(""))."
							".$back."
							name: '".$value['fname']."'
							}");
				break;}
				case 'fckeditor':{
					$js[$value['fname']] =preg_replace("/[\s]{2,}/","","{
						xtype:\"textarea\",
						".(($value['id'])?("id:'".$value['id']."',"):(""))."
						value:\"".(grv($value['qzfs'],$value['blm'],adxx($fdada[$value['fname']])))."\",
						".(($value['width'])?("width:".$value['width'].","):("anchor:'98%',"))."
						".(($config['height'])?("height:".$config['height'].","):("height:300,"))."
						fieldLabel:'".$value['name']."',
						".$back."
						listeners:{
						     focus:function(f){
								 				var myMask = new Ext.LoadMask(Ext.getBody(), {msg:'请等待'});
												myMask.show();
												var w=f.getSize();
												   fckEditor = new FCKeditor('".$value['fname']."') ;
												   fckEditor.Height=".(($config['height'])?($config['height']):(300)).";
												   fckEditor.Width=".(($value['width'])?($value['width']):(800)).";
												fckEditor.SkinPath = '/Plug-in/fck/editor/skins/silver/' ;
												fckEditor.BasePath = '/Plug-in/fck/' ;
												fckEditor.Config['ToolbarStartExpanded'] = ".(($config['zhed'])?("false"):('true')).";
												".(($config['STR'])?($config['STR']):(""))."
												fckEditor.ReplaceTextarea() ;
												myMask.hide();
						                     }
						                   },
						name: '".$value['fname']."'
						}");
					$fckplugin.="try{var fckobj_temp = FCKeditorAPI.GetInstance('".$value['fname']."');
										 fckobj_temp.UpdateLinkedField();}catch(err){
														};";
					$plugurl[] = '/Plug-in/fck/fckeditor.js';	  // fckEditor.ReplaceTextarea() ;
				break;}
				case 'kindeditor':{
					$yuan = array("</script>", "vegetables", "fiber");
					$tyuan   = array("<\/script>", "beer", "ice cream");

					$js[$value['fname']] =preg_replace("/[\s]{2,}/","","{
						xtype:\"textarea\",
						id:'".$value['fname']."',
						".$back."
						value:\"".(grv($value['qzfs'],$value['blm'],str_replace($yuan, $tyuan,adxx(preg_replace("'([\r\n])[\s]+'", "", $fdada[$value['fname']])))))."\",
						".(($value['width'])?("width:".$value['width'].","):("anchor:'98%',"))."
						".(($config['height'])?("height:".$config['height'].","):("height:300,"))."
						fieldLabel:'".$value['name']."',
						listeners:{
							   render:function(f){
												try{KE.show({id : '".$value['fname']."',
												width :".(($value['width'])?("'".$value['width']."px'"):('70%')).",
												height : ".(($config['height'])?("'".$config['height']."px'"):('300px')).", 
												".(($config['STR'])?($config['STR']):(""))."
												".(($config['jd'])?("resizeMode : 1,
													allowPreviewEmoticons : false,
													allowUpload : false,
													items : [
													'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
													'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
													'insertunorderedlist', '|', 'emoticons', 'image', 'link'],"):(""))."
												filterMode : false});}catch(err){
														};
								   				}
						                   },
						
						name: '".$value['fname']."'
						}");
					$fckplugin.="KE.util.setData('".$value['fname']."');";
					$plugurl[] = '/Plug-in/kind/kindeditor.js';	  // fckEditor.ReplaceTextarea() ;
				break;}
				case 'datefield':{
					if(is_numeric($fdada[$value['fname']])){
							$fdada[$value['fname']]=date($config['zqgs'],$fdada[$value['fname']]);				 
											 }
						$js[$value['fname']] ="{
							xtype: 'datefield',
							".$back."
							value:\"".(grv($value['qzfs'],$value['blm'],adxx($fdada[$value['fname']])))."\",
							fieldLabel:'".$value['name']."',
							".(($value['id'])?("id:'".$value['id']."',"):(""))."
							".(($value['width'])?("width:".$value['width'].","):(""))."
							disabledDays :[".@implode(',',$config['pbxq'])."],
							".((!$value['yxwk'])?("allowBlank:false,blankText:'".adxx($value['ts'])."',"):(""))."
							".(($config['zwxs'])?("readOnly:'true',"):(""))."
							".(($config['STR'])?("".$config['STR'].""):(""))."
							".(($config['zqgs'])?("format:'".$config['zqgs']."',"):(""))."
							name: '".$value['fname']."'
							}";
		        if($config['zwxs']==1){$plugjs[] ='Date.dayNames = ["日", "一", "二", "三", "四", "五", "六"];
						    if (Ext.DatePicker) {
						        Ext.apply(Ext.DatePicker.prototype, {
						            todayText: "今天",
						            minText: "日期在最小日期之前",
						            maxText: "日期在最大日期之后",
						            disabledDaysText: "",
						            disabledDatesText: "",
						            monthNames: Date.monthNames,
						            dayNames: Date.dayNames,
						            nextText: "下月 (Control+Right)",
						            prevText: "上月 (Control+Left)",
						            monthYearText: "选择一个月 (Control+Up/Down 来改变年)",
						            todayTip: "{0} (Spacebar)",
						            okText: "确定",
						            cancelText: "取消",
						            format: "y年m月d日"
						        });
   					}';}
				break;}
				case 'swfupload':{
					$js[$value['fname']] ="{
							xtype: '{$value['type']}',
							".$back."
			                name: '{$value['fname']}',
			                id: '{$value['fname']}',
			                fieldLabel: '{$value['name']}',
			                anchor:'99%',
			                height: {$config['height']}
						}";
				break;}
				case 'combo':{
								$tempxx = json_decode($value['zyz'],true);
								$config_num = count($tempxx);
								$items='';
								if($config_num != 0){
									foreach($tempxx as $key => $data){
										if($data['ck']=='1'){
											$fdada[$value['fname']]?$fdada[$value['fname']]:$fdada[$value['fname']]=$data['xv'];}
											$items.= "['".$data['xv']."','".$data['yv']."']";
										if($key < $config_num-1){
											$items.= ",";
										}
									}
								}
						$js[$value['fname']] ="{
							".$back."
							value:\"".(grv($value['qzfs'],$value['blm'],adxx($fdada[$value['fname']])))."\",
							fieldLabel:'".$value['name']."',
							".(($value['id'])?("id:'".$value['id']."',"):(""))."
							".(($value['width'])?("width:".$value['width'].","):(""))."
							".((!$value['yxwk'])?("allowBlank:false,blankText:'".adxx($value['ts'])."',"):(""))."
							".(($config['readonly'])?("readOnly:'true',"):(""))."
							typeAhead: true,
							name: '".$value['fname']."_',
							hiddenName : '".$value['fname']."',
							editable: false,xtype: 'combo',
							store:new Ext.data.SimpleStore({
											fields:['name','value'],
											data:[".$items."]}),
							mode:'local',
					        displayField:'name',
					        selectOnFocus:true,
					        valueField :'value',
							".(($config['STR'])?("".$config['STR'].""):(""))."
					        triggerAction:'all'

							}";
				break;}
				case 'radiogroup':{
								$tempxx = json_decode($value['zyz'],true);
								$config_num = count($tempxx);
								if($config_num != 0){
									$items='';
									if($_GET['id']!=''){
									foreach($tempxx as $key => $data){
										if($data['yv']==$fdada[$value['fname']]){
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."',inputValue:'".$data['yv']."',checked: true}";}else{
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."',inputValue:'".$data['yv']."'}";}
										if($key < $config_num-1){
											$items.= ",";
										}
									}
									}else{
									foreach($tempxx as $key => $data){
										if($data['ck']=='1'){
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."',inputValue:'".$data['yv']."',checked: true}";}else{
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."',inputValue:'".$data['yv']."'}";}
										if($key < $config_num-1){
											$items.= ",";
										}
									}
										}
								}
						$js[$value['fname']] ="{
							xtype: 'radiogroup',
							".$back."
							".(($value['width']&&$value['width']<=$config_num)?("columns:".$value['width'].","):(""))."
							".(($config['vertical'])?("vertical: true,"):(""))."
							".((!$value['yxwk'])?("allowBlank:false,blankText:'".adxx($value['ts'])."',"):(""))."
							anchor: '95%',
							 items: [".$items."],
							".(($config['STR'])?("".$config['STR'].""):(""))."
							fieldLabel:'".$value['name']."'
							}";
				break;}
				case 'recommend':{
							$items='';
							if(1==$fdada[$value['fname']]){
								$items.= "{boxLabel:'推荐中',name:'".$value['fname']."',inputValue:'1',checked: true},";
								$items.= "{boxLabel:'不推荐',name:'".$value['fname']."',inputValue:'0'}";
								}else{
								$items.= "{boxLabel:'推荐中',name:'".$value['fname']."',inputValue:'1'},";
								$items.= "{boxLabel:'不推荐',name:'".$value['fname']."',inputValue:'0',checked: true}";
									}
								
						$js[$value['fname']] ="{
							xtype: 'radiogroup',
							".$back."
							".((!$value['yxwk'])?("allowBlank:false,blankText:'".adxx($value['ts'])."',"):(""))."
							anchor: '95%',
							 items: [".$items."],
							".(($config['STR'])?("".$config['STR'].""):(""))."
							fieldLabel:'".$value['name']."'
							}";
				break;}
				case 'checkboxgroup':{
								$tempxx = json_decode($value['zyz'],true);
								$config_num = count($tempxx);
								if($config_num != 0){
									$items='';
									if($_GET['id']!=''){
										$xsarray=explode("#_#",$fdada[$value['fname']]);
									foreach($tempxx as $key => $data){
										if(in_array($data['yv'],$xsarray)){
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."[".$key."]',inputValue:'".$data['yv']."',checked: true}";}else{
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."[".$key."]',inputValue:'".$data['yv']."'}";}
										if($key < $config_num-1){
											$items.= ",";
										}
									}
									}else{
									foreach($tempxx as $key => $data){
										if($data['ck']=='1'){
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."[".$key."]',inputValue:'".$data['yv']."',checked: true}";}else{
											$items.= "{boxLabel:'".$data['xv']."',name:'".$value['fname']."[".$key."]',inputValue:'".$data['yv']."'}";}
										if($key < $config_num-1){
											$items.= ",";
										}
									}
										}
								}
						$js[$value['fname']] ="{
							xtype:'checkboxgroup',
							".$back."
							".(($value['width']&&$value['width']<=$config_num)?("columns:".$value['width'].","):(""))."
							".(($config['vertical'])?("vertical: true,"):(""))."
							".((!$value['yxwk'])?("allowBlank:false,blankText:'".adxx($value['ts'])."',"):(""))."
							anchor: '95%',
							 items: [".$items."],
							".(($config['STR'])?("".$config['STR'].""):(""))."
							fieldLabel:'".$value['name']."'
							}";
				break;}
				default:{
						$js[$value['fname']] ="{
							xtype: 'textfield',
							fieldLabel: '{$value['name']}',
							name: '{$value['fname']}',
							".$back."
							anchor:'60%'
						}";
						break;
						}
		  }
		
		Tr($plugurl,'plugurl');
		Tr($plugjs,'plugjs');
		Tr($fckplugin,'fckplugin');
		if($_GET['id']==0){
			Tr('添加','action');
		}else{
			Tr('编辑','action');
		}
			Tr($js[$value['fname']],'fcf');					  
	Ts('zdgx/add.html');
	break;}
	case 'insert':{
	Ts('user/list.html');
	break;}
	default:{
	Ts('zdgx/password.html');
	break;
	}
}

?>
